<?php

use yii\db\Migration;

class m171107_085002_create_goods_price extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%goods_price}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'goods_id' => $this->integer()->defaultValue(0)->comment('商品id'),
                'price_name' => $this->string(50)->defaultValue(null)->comment('价格名称'),
                'lesson' => $this->smallInteger(3)->defaultValue(0)->comment('课次数'),
                'lesson_price' => $this->decimal(10,2)->defaultValue(0)->comment('课次价格'),
                'distribution_way' => $this->smallInteger(1)->defaultValue(0)->comment('分成方式 0 固定 1 比例'),
                'distribution_proportion' => $this->smallInteger(4)->defaultValue(0)->comment('分成金额或比例'),
                'subsidy_type' => $this->smallInteger(1)->defaultValue(0)->comment('课时补贴方式（1，按学生 2 课程）'),
                'subsidy_money' => $this->decimal(10,2)->defaultValue(0)->comment('补贴金额'),
                'is_scholarship' => $this->smallInteger(1)->defaultValue(0)->comment('是否支持奖学金 1 是 2 否'),
                'scholarship' => $this->decimal(10,2)->defaultValue(0)->comment('可使用奖学金金额'),
                'admin_id' => $this->integer()->defaultValue(0)->comment('操作人'),
                'status' => $this->smallInteger(2)->defaultValue(1)->comment('状态（0禁用 1 启用）'),
                'art_lesson' => $this->smallInteger(3)->defaultValue(0)->comment('艺教学课次）'),
                'art_lesson_price' => $this->decimal(10,2)->defaultValue(0)->comment('艺教学价格'),
                'is_art_scholarship' => $this->smallInteger(2)->defaultValue(0)->comment('艺教学是否可用奖学金1 是 2 否'),
                'art_scholarship' => $this->decimal(10,2)->defaultValue(0)->comment('艺教学用奖学金'),
                'created_at' => $this->integer()->defaultValue(0)->comment('创建时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%goods_price}}');
        }
    }
}
